﻿import paramiko

cmd = 'tcpdump -i ens33 -c 3'


# cmd = ''


def tssh(ip, user, pwd):
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(ip, 22, user, pwd, timeout=5)
        stdin, stdout, stderr = ssh.exec_command(cmd, get_pty=True)
        while not stdout.channel.exit_status_ready():  # 循环条件为返回为 False
            result = stdout.readline()
            print("result:%s" % result)
            print("status1_status:%s" % stdout.channel.exit_status_ready())
            if stdout.channel.exit_status_ready():
                a = stdout.readlines()
                break
        ssh.close()
    except Exception as e:
        print(e)


if __name__ == '__main__':
    tssh('192.168.64.148', 'root', '123456')
